package com.zhishu.api.impl;

import com.zhishu.api.ITaskApi;

import com.zhishu.system.service.TaskService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhishu.system.util.RedisClinet;

import redis.clients.jedis.Jedis;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class TaskApiImpl implements ITaskApi {
    private static final Logger LOGGER = Logger.getLogger(TaskApiImpl.class);
    @Resource
    private TaskService taskService;

    @ResponseBody
    @RequestMapping(value = "", method = RequestMethod.POST)
    public boolean addTask(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {

        String requestId = httpRequest.getParameter("request_id");
        String url = httpRequest.getParameter("url");
        String uuid = httpRequest.getParameter("uuid");
        //如果不存在 返回null
        String userId = httpRequest.getParameter("user_id");


        return taskService.addTask(requestId, url, uuid, userId);
    }

    @Override
    public Boolean redisStore(String requestId, String html) {
        Boolean flag = false;
        Jedis redis = new Jedis("60.205.144.251", 6379);
        redis.auth("admin123");
        redis.set(requestId, html);
        String temp = RedisClinet.getInstance().set(html, requestId);
        System.out.println(temp);
        return null;
    }

    public static void main(String args[]) {
        try {
            String requestId = "aa";
            String html = "abcdefg";
            Jedis redis = new Jedis("60.205.144.251", 6379);
            redis.auth("admin123");
            redis.set(requestId, html);
            String temp = RedisClinet.getInstance().set(html, requestId);
            System.out.println(temp);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}
